package com.htht.job.admin.controller.productfileinfo;

import com.alibaba.fastjson.JSON;
import com.htht.job.core.api.DubboService;
import com.htht.job.core.biz.model.ReturnT;
import com.htht.job.executor.model.fileinfo.FileInfo;
import com.htht.job.executor.model.product.Product;
import com.htht.job.executor.model.productfileinfo.ProductFileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by zzj on 2018/1/3.
 */
@Controller
@RequestMapping("/productfileinfo")
public class ProductFileInfoController {
    @Autowired
    private DubboService dubboService;
    @RequestMapping
    public String index(Model model) {
        return "/productfileinfo/productfileinfo.index";
    }
    @RequestMapping("/pageList")
    @ResponseBody
    public Map<String, Object> pageList(@RequestParam(required = false, defaultValue = "0") int start,
                                        @RequestParam(required = false, defaultValue = "10") int length, ProductFileInfo productFileInfo) {
        if(start!=0){
            start=start/length;
        }
        return dubboService.pageListProductFileInfo(start, length, productFileInfo);
    }
    @RequestMapping("/saveProductFileInfo")
    @ResponseBody
    public ReturnT<String> saveProductFileInfo(ProductFileInfo productFileInfo){
        ProductFileInfo p=dubboService.saveProductFileInfo(productFileInfo);
        if(null!=p.getId()){
            return ReturnT.SUCCESS;
        }else{
            return ReturnT.FAIL;
        }
    }
    @RequestMapping("/deleteProductFileInfo")
    @ResponseBody
    public ReturnT<String> deleteProductFileInfo(String id){
        ProductFileInfo p=dubboService.deleteProductFileInfo(id);
        if(null!=p.getId()){
            return ReturnT.SUCCESS;
        }else{
            return ReturnT.FAIL;
        }
    }
    @RequestMapping("/findFileInfoByWhere/{id}")
    @ResponseBody
    public List<FileInfo> findFileInfoByWhere(@PathVariable String id){
        List<FileInfo> fileInfos=dubboService.findFileInfoByWhere(id);
        return fileInfos;
    }
}
